package com.yunxiao.cloud.common.plugin;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.StringUtils;

/**
 * @description: 按照一定规则生成错误码
 * @date: 2019/12/20 09:18
 * @author: yunxiao
 * @version: 1.0
 */
public class CodeGenerator {
    private static Logger logger = LoggerFactory.getLogger(CodeGenerator.class);
    public CodeGenerator() {
        //do nothing
    }

    /**
     * 生成错误码 类型+五位编号（从1开始，不够前补0）
     * @param errorType 错误码类型
     * @param errorNo 错误码编号
     * @return 错误码
     */
    public static String generateErrorCode(String errorType, String errorNo) {
        String newEquipmentNo = "";

        if(!StringUtils.isEmpty(errorNo)){
            int newEquipment = Integer.parseInt(errorNo);
            newEquipmentNo = String.format("%s%05d", errorType, newEquipment);
        }

        return newEquipmentNo;
    }

    public static void main(String[] args) {

        String reaul = generateErrorCode("112","1");
        logger.info(reaul);
    }
}
